package com.hh.demo.mq;

import com.hh.demo.domain.MessageSms;
import com.hh.demo.domain.MessageStation;
import com.hh.demo.service.IMessageSmsService;
import com.hh.demo.service.IMessageStationService;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.Date;

/**
 * @author 黄浩
 * @create 2022-07-25 22:33
 */
@Component
@RocketMQMessageListener(consumerGroup = "service-common-stationmessage-consumer",
        topic = "course-topic",
        selectorExpression = "course-tags"
)
public class StationMessageMQConsumer implements RocketMQListener<MessageExt> {

    @Resource
    private IMessageStationService messageStationService;

    @Override
    public void onMessage(MessageExt messageExt) {
        String message = new String(messageExt.getBody(), StandardCharsets.UTF_8);
        MessageStation messageStation = new MessageStation();
        messageStation.setIsread(0);
        messageStation.setTitle("课程上线通知");
        messageStation.setContent(message);
        messageStation.setSendTime(new Date());
        messageStationService.insert(messageStation);
    }
}
